<table border="0" class="tableborder3">
<?php
$row=0;
$zaos[$line[1]]=0;
$jies[$line[1]]=0;

$query="select 0,CONVERT(varchar(10),a.dhrq,120),sum(b.shisje) from sys_jhdh a,sys_jhsj b,sys_unit unit,sys_cp cp where a.lx in(2) and a.id=b.dhid and a.unit=unit.id and b.mc=cp.id $TJ group by a.dhrq order by a.dhrq";
$result=sqlsrv_query($conn,$query);
while($line=sqlsrv_fetch_array($result))
{
	$zaos[$line[1]]=$line[2];
}
sqlsrv_free_stmt($result);
$query="select 0,CONVERT(varchar(10),a.dhrq,120),sum(b.shisje) from sys_jhdh a,sys_jhsj b,sys_unit unit,sys_cp cp where a.lx in(12) and a.id=b.dhid and a.unit=unit.id and b.mc=cp.id $TJ group by a.dhrq order by a.dhrq";
$result=sqlsrv_query($conn,$query);
while($line=sqlsrv_fetch_array($result))
{
	$jies[$line[1]]=$line[2];
}
sqlsrv_free_stmt($result);


$query="select 0,CONVERT(varchar(10),a.dhrq,120),sum(b.jiesje) from sys_jhdh a,sys_jhsj b,sys_unit unit,sys_cp cp where a.lx in(2,12) and a.id=b.dhid and a.unit=unit.id and b.mc=cp.id $TJ group by a.dhrq order by a.dhrq";
$result=sqlsrv_query($conn,$query);
while($line=sqlsrv_fetch_array($result))
{
	$xiaos[$line[1]]=$line[2];
}
sqlsrv_free_stmt($result);

$CS=explode('#',$_SESSION['mac']);
$HJ=explode(',',$CS[1]);
$KD=explode(',',$CS[2]);
$AL=explode(',',$CS[3]);
$Column=count($HJ);//取的总列数
$query=$CS[0];
$result=sqlsrv_query($conn,$query);
$tp1='';
$mid=0;
$row=0;
while($line=sqlsrv_fetch_array($result))
{
	$hjaa=$zaos[$line[1]]+$jies[$line[1]];
	echo "<tr>";
	echo "<td align=left width=20% height=22>".$line[1]."</td>";
	echo "<td align=right width=16%>".$zaos[$line[1]]."</td>";
	echo "<td align=right width=16%>".$jies[$line[1]]."</td>";
	echo "<td align=right width=16%>".$hjaa."</td>";
	echo "<td align=right width=16%>".$xiaos[$line[1]]."</td>";
	echo "<td align=right width=16%></td>";
	echo "</tr>";
}
sqlsrv_free_stmt($result);
?>
</table>